<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var tupleSame = function (nums) {
      let obj = {}
      //双循环对象记录相同数次数
      for (let i = 0; i < nums.length - 1; i++) {
        for (let j = i + 1; j < nums.length; j++) {
          let num = nums[i] * nums[j]
          obj[num] = obj[num] + 1 || 1
        }
      }
      //取出次数
      let arr = Object.values(obj)
      let res = 0
      //次数决定有几对数相乘值相同，每两对值算一种组合，需要计算组合总数
      arr.forEach(v => {
        v > 1 ? res = res + sum(v) : ''
      })
      //计算组合数的和；比如a:[3,4],b:[2,6],c:[12,1],也就是求a,b,c三个的组合次数
      function sum(n) {
        let s = 0
        for (let i = 0; i < n; i++) {
          s += i
        }
        return s
      }
      //每种组合有四个数字，数字交换位置可以有八种排序方式
      return res * 8
    };
    console.log(tupleSame(nums = [2, 3, 4, 6]))
  </script>
</body>

</html>